#ifndef GW_ELF_H
#define GW_ELF_H


/* 32-bit ELF base types. */
typedef unsigned int Elf32_Addr;
typedef unsigned short Elf32_Half;
typedef unsigned int Elf32_Off;
typedef signed int Elf32_Sword;
typedef unsigned int Elf32_Word;

#define EI_NIDENT (16)

// 52 byte    
typedef struct
{
  unsigned char     ident[EI_NIDENT];        /* Magic number and other info */
  Elf32_Half        type;                    /* Object file type */
  Elf32_Half        machine;                 /* Architecture */
  Elf32_Word        version;                 /* Object file version */
  Elf32_Addr        entry;                   /* Entry point virtual address */
  Elf32_Off         phoff;                   /* Program header table file offset */
  Elf32_Off         shoff;                   /* Section header table file offset */
  Elf32_Word        flags;                   /* Processor-specific flags */
  Elf32_Half        ehsize;                  /* ELF header size in bytes */
  Elf32_Half        phentsize;               /* Program header table entry size */
  Elf32_Half        phnum;                   /* Program header table entry count */
  Elf32_Half        shentsize;               /* Section header table entry size */
  Elf32_Half        shnum;                   /* Section header table entry count */
  Elf32_Half        shstrndx;                /* Section header string table index */
} Elf32_Ehdr;

/* Program segment header.  */

// 32 byte    
typedef struct
{
  Elf32_Word        type;                 /* Segment type */
  Elf32_Off         offset;               /* Segment file offset  Segment对应的内容在文件的偏移*/
  Elf32_Addr        vaddr;                /* Segment virtual address Segment在内存中的线性地址*/
  Elf32_Addr        paddr;                /* Segment physical address */
  Elf32_Word        filesz;               /* Segment size in file */
  Elf32_Word        memsz;                /* Segment size in memory */
  Elf32_Word        flags;                /* Segment flags */
  Elf32_Word        align;                /* Segment alignment */
} Elf32_Phdr;

#define        PT_NULL           0                /* Program header table entry unused */
#define        PT_LOAD           1                /* Loadable program segment */
#define        PT_DYNAMIC        2                /* Dynamic linking information */
#define        PT_INTERP         3                /* Program interpreter */
#define        PT_NOTE           4                /* Auxiliary information */
#define        PT_SHLIB          5                /* Reserved */
#define        PT_PHDR           6                /* Entry for header table itself */
#define        PT_TLS            7                /* Thread-local storage segment */
#define        PT_NUM            8                /* Number of defined types */


#endif /* GW_ELF_H */